from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-27 14:11:48.689985
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 27, Apr, 2021
Time: 14:11:55
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8059
Nobs: 274.000 HQIC: -48.5163
Log likelihood: 3302.89 FPE: 5.28299e-22
AIC: -48.9927 Det(Omega_mle): 3.82622e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.421044 0.121460 3.467 0.001
L1.Burgenland 0.072170 0.060295 1.197 0.231
L1.Kärnten -0.225725 0.053372 -4.229 0.000
L1.Niederösterreich 0.090204 0.130088 0.693 0.488
L1.Oberösterreich 0.226084 0.125145 1.807 0.071
L1.Salzburg 0.267972 0.069037 3.882 0.000
L1.Steiermark 0.110654 0.087775 1.261 0.207
L1.Tirol 0.120432 0.060735 1.983 0.047
L1.Vorarlberg -0.034494 0.055713 -0.619 0.536
L1.Wien -0.038986 0.112707 -0.346 0.729
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.454347 0.140559 3.232 0.001
L1.Burgenland 0.003677 0.069776 0.053 0.958
L1.Kärnten 0.330861 0.061764 5.357 0.000
L1.Niederösterreich 0.104089 0.150543 0.691 0.489
L1.Oberösterreich -0.064212 0.144823 -0.443 0.657
L1.Salzburg 0.220521 0.079893 2.760 0.006
L1.Steiermark 0.092915 0.101577 0.915 0.360
L1.Tirol 0.138331 0.070285 1.968 0.049
L1.Vorarlberg 0.149504 0.064473 2.319 0.020
L1.Wien -0.419908 0.130429 -3.219 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.274251 0.061396 4.467 0.000
L1.Burgenland 0.100934 0.030478 3.312 0.001
L1.Kärnten -0.013561 0.026978 -0.503 0.615
L1.Niederösterreich 0.081198 0.065757 1.235 0.217
L1.Oberösterreich 0.282483 0.063259 4.466 0.000
L1.Salzburg 0.017531 0.034897 0.502 0.615
L1.Steiermark -0.001835 0.044369 -0.041 0.967
L1.Tirol 0.070693 0.030700 2.303 0.021
L1.Vorarlberg 0.075706 0.028162 2.688 0.007
L1.Wien 0.115405 0.056972 2.026 0.043
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214052 0.058852 3.637 0.000
L1.Burgenland 0.026045 0.029215 0.891 0.373
L1.Kärnten 0.010096 0.025861 0.390 0.696
L1.Niederösterreich 0.057007 0.063032 0.904 0.366
L1.Oberösterreich 0.396863 0.060637 6.545 0.000
L1.Salzburg 0.078598 0.033451 2.350 0.019
L1.Steiermark 0.129022 0.042530 3.034 0.002
L1.Tirol 0.049413 0.029428 1.679 0.093
L1.Vorarlberg 0.081453 0.026995 3.017 0.003
L1.Wien -0.042838 0.054611 -0.784 0.433
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487641 0.115251 4.231 0.000
L1.Burgenland 0.097661 0.057213 1.707 0.088
L1.Kärnten 0.010633 0.050643 0.210 0.834
L1.Niederösterreich 0.004452 0.123438 0.036 0.971
L1.Oberösterreich 0.124494 0.118748 1.048 0.294
L1.Salzburg 0.055405 0.065508 0.846 0.398
L1.Steiermark 0.066588 0.083288 0.799 0.424
L1.Tirol 0.207837 0.057630 3.606 0.000
L1.Vorarlberg 0.032866 0.052865 0.622 0.534
L1.Wien -0.080528 0.106946 -0.753 0.451
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209563 0.091130 2.300 0.021
L1.Burgenland -0.012295 0.045239 -0.272 0.786
L1.Kärnten -0.007950 0.040044 -0.199 0.843
L1.Niederösterreich -0.015856 0.097604 -0.162 0.871
L1.Oberösterreich 0.418015 0.093895 4.452 0.000
L1.Salzburg 0.012553 0.051798 0.242 0.809
L1.Steiermark -0.028133 0.065857 -0.427 0.669
L1.Tirol 0.162187 0.045569 3.559 0.000
L1.Vorarlberg 0.057721 0.041801 1.381 0.167
L1.Wien 0.210081 0.084563 2.484 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222578 0.110689 2.011 0.044
L1.Burgenland 0.019472 0.054948 0.354 0.723
L1.Kärnten -0.070393 0.048639 -1.447 0.148
L1.Niederösterreich -0.062854 0.118552 -0.530 0.596
L1.Oberösterreich 0.022554 0.114047 0.198 0.843
L1.Salzburg 0.081602 0.062915 1.297 0.195
L1.Steiermark 0.324978 0.079991 4.063 0.000
L1.Tirol 0.461335 0.055349 8.335 0.000
L1.Vorarlberg 0.144556 0.050772 2.847 0.004
L1.Wien -0.140669 0.102712 -1.370 0.171
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205721 0.132275 1.555 0.120
L1.Burgenland 0.042403 0.065663 0.646 0.518
L1.Kärnten -0.075276 0.058124 -1.295 0.195
L1.Niederösterreich 0.106668 0.141670 0.753 0.451
L1.Oberösterreich 0.013619 0.136287 0.100 0.920
L1.Salzburg 0.194799 0.075184 2.591 0.010
L1.Steiermark 0.131350 0.095590 1.374 0.169
L1.Tirol 0.056646 0.066142 0.856 0.392
L1.Vorarlberg 0.107022 0.060673 1.764 0.078
L1.Wien 0.224991 0.122742 1.833 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.540228 0.072764 7.424 0.000
L1.Burgenland -0.013783 0.036121 -0.382 0.703
L1.Kärnten -0.015308 0.031974 -0.479 0.632
L1.Niederösterreich 0.097231 0.077932 1.248 0.212
L1.Oberösterreich 0.303315 0.074971 4.046 0.000
L1.Salzburg 0.013418 0.041358 0.324 0.746
L1.Steiermark -0.045641 0.052584 -0.868 0.385
L1.Tirol 0.081165 0.036385 2.231 0.026
L1.Vorarlberg 0.103452 0.033376 3.100 0.002
L1.Wien -0.059732 0.067520 -0.885 0.376
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.160804 0.095934 0.164202 0.220476 0.076427 0.086705 0.002018 0.155968
Kärnten 0.160804 1.000000 0.056070 0.209440 0.182914 -0.063921 0.174804 0.021420 0.305873
Niederösterreich 0.095934 0.056070 1.000000 0.246205 0.085522 0.320406 0.149398 0.020818 0.313582
Oberösterreich 0.164202 0.209440 0.246205 1.000000 0.305359 0.259916 0.096612 0.062194 0.139378
Salzburg 0.220476 0.182914 0.085522 0.305359 1.000000 0.152160 0.062009 0.089877 0.017953
Steiermark 0.076427 -0.063921 0.320406 0.259916 0.152160 1.000000 0.097956 0.100229 -0.101384
Tirol 0.086705 0.174804 0.149398 0.096612 0.062009 0.097956 1.000000 0.153962 0.155028
Vorarlberg 0.002018 0.021420 0.020818 0.062194 0.089877 0.100229 0.153962 1.000000 -0.009908
Wien 0.155968 0.305873 0.313582 0.139378 0.017953 -0.101384 0.155028 -0.009908 1.000000